package com.zxy.demo.common;

/**
 * 标准返回类型
 * @author ZENG.XIAO.YAN
 * @version 1.0
 */
public class ModelResult<T> {
	private int code;
	private String msg = "";
	private boolean status;
	private T model;
	
	public ModelResult() {
		this.code = ErrorCodeEnum.OK.getCode();
		this.msg = ErrorCodeEnum.OK.getMsg();
		this.status = true;
		this.model = null;
	}
	public ModelResult(int code, String msg, boolean status, T model) {
		super();
		this.code = code;
		this.msg = msg;
		this.status = status;
		this.model = model;
	}
	
	public ModelResult(ErrorCodeEnum errorCode, boolean status, T model) {
		super();
		this.code = errorCode.getCode();
		this.msg = errorCode.getMsg();
		this.status = status;
		this.model = model;
	}

	/** setter and getter method */
	public int getCode() {
		return code;
	}

	public void setCode(int code) {
		this.code = code;
	}

	public boolean isStatus() {
		return status;
	}

	public void setStatus(boolean status) {
		this.status = status;
	}

	public T getModel() {
		return model;
	}

	public void setModel(T model) {
		this.model = model;
	}

	public String getMsg() {
		return msg;
	}

	public void setMsg(String msg) {
		this.msg = msg;
	}
	
	// 下面的两个方法比较常用,故抽取出来了
	public void setWithDefaultErrorCodeAndMsg() {
		this.code = ErrorCodeEnum.ERROR.getCode();
		this.msg = ErrorCodeEnum.ERROR.getMsg();
		this.status = false;
		this.model = null;
	}
	
	public void setMsgWithDefaultErrorCode(String msg) {
		this.code = ErrorCodeEnum.ERROR.getCode();
		this.msg = msg;
		this.status = false;
		this.model = null;
	}
	
	
}
